/**
 * Copyright (c) 2010, QinJian
 * All rights reserved.
 */
package com.q.course.web.category;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.q.course.entity.category.Category;
import com.q.course.service.category.CategoryService;

/**
 * @author 覃健,Email:j411@qq.com
 *
 */
@Controller
@RequestMapping("/category")
public class CategoryController {

	@Autowired
	private CategoryService categoryService;
	
	@ResponseBody
	@RequestMapping( value="/save.do" , method = RequestMethod.POST )
	public Long saveCategory(Category category){
		
		return categoryService.saveCategory(category);
	}
	
	@ResponseBody
	@RequestMapping( value="/getcategories.do" , method = RequestMethod.GET )
	public List<Category> getCategories(@RequestParam(value = "type") long type){
		
		return categoryService.getCategories(type);
	}
	
	@ResponseBody
	@RequestMapping( value="/getcategorynopar.do" , method = RequestMethod.GET )
	public List<Category> getCategoriesParentIsNull(@RequestParam(value = "type") long type, @RequestParam(value = "categoryId") Long categoryId){
		return categoryService.getCategoriesParentIsNull(type, categoryId);
	}
	
	/**
	 * 通过班级找班级课程
	 * @param classId
	 * @return
	 */
	@ResponseBody
	@RequestMapping( value="/getcoursebyclass.do" , method = RequestMethod.GET )
	public List<Category> getCategoriesByClass(@RequestParam(value = "classId") Long classId){
		return categoryService.getCategoriesByClass(classId);
	}
	
	@ResponseBody
	@RequestMapping( value="/delcategory.do" , method = RequestMethod.GET )
	public boolean deleteCategory(Category category){
		return categoryService.deleteCategory(category);
	}
}
